import {BASEURL} from '@/services/api'
import {request, METHOD} from '@/utils/request'
import axios from "axios";

/*
* 按条件获取资源列表searchBooks
* */
export async function getBooks(name,author,start,end){
    return request(BASEURL+'/books/books',METHOD.POST,{
        name:name,
        author:author,
        start:start,
        end:end
    })
}

export async function searchBooks(name,author,start,end,cateId){
    return request(BASEURL+'/books/searchBooks',METHOD.POST,{
        name:name,
        author:author,
        start:start,
        end:end,
        cateId:cateId
    })
}

/*
*添加图书
* */
export async function addBook(name,link,description,cateId){
    return request(BASEURL+'/books/addBook',METHOD.POST,{
        name:name,
        link:link,
        description:description,
        cateId:cateId,
    })
}
/*
* 资源上传图片
* */
export async function uploadCover(id,file) {
    return axios({
        headers: {'Content-Type': 'multipart/form-data'},
        url: BASEURL + '/books/uploadCover/'+id,
        method: 'post',
        data: file
    })
}
/*
* 修改资源状态
* */
export async function updateBookState(id){
    return request(BASEURL+'/books/update/'+id,METHOD.GET)
}

/*
* 根据ID删除资源
* */
export async function deleteBookById(id){
    return request(BASEURL+'/books/delete/'+id,METHOD.DELETE)
}
/*
* 根据ID获取资源信息
* */
export async function getBookById(id){
    return request(BASEURL+'/books/getById/'+id,METHOD.GET)
}

/*
* 修改资源信息
* */
export async function updateBookInfo(id,name,link,description,cateId){
    return request(BASEURL+'/books/updateBook',METHOD.POST,{
        id:id,
        name:name,
        link:link,
        description:description,
        cateId:cateId
    })
}
/*
* 点赞
* */
export async function pickOk(bookId){
    return request(BASEURL+'/like/'+bookId,METHOD.POST)
}
/*
* 获取总的点赞数
* */
export async function totalPickOk(bookId){
    return request(BASEURL+'/like/total/'+bookId,METHOD.GET)
}

/*
* 获取个人分享的资源
* */
export async function getMyBooks(){
    return request(BASEURL+'/books/getSelfBooks',METHOD.POST)
}
/*
* 获取个人收藏
* */
export async function getAllLike(){
    return request(BASEURL+'/books/getAllLike',METHOD.GET)
}
